package com.freedom.base.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Description: Swagger配置类
 * <p>CreateTime: 2023-03-11 上午 1:57</p>
 * <p>Email: 2396598264@qq.com</p>
 *
 * @author Chb
 */

@EnableSwagger2
@EnableKnife4j
@Configuration
public class SwaggerConfig {
    /**
     * Swagger-API文档配置
     *
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .enable(true)
                .apiInfo(apiInfo())
                .groupName("FosuClassroom-API")
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * API文档信息
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("佛大课堂项目接口文档")
                .description("此文档为佛大课堂项目中所有接口的定义说明")
                .termsOfServiceUrl("")
                .contact(new Contact("freedom", "", "2396598264@qq.com"))
                .version("1.0")
                .build();
    }
}
